<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>分单号查询</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="billNativeCodeForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span>分单号：</span>
                <input id="keyId" class="mini-textbox" emptyText="分单号" />
                <span class="separator"></span>
                <span>使用状态：</span>
                <input id="keyUseStatusId" name="keyUseStatusId" class="mini-combobox" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." />
                <span class="separator"></span>
                <span>领单部门：</span>
                <input id="keyDepartmentId" name="keyDepartmentId" class="mini-treeselect" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
                      required="false" allowInput="true" showNullItem="true" nullItemText="请选择..."/>

                <span class="separator"></span>
                <span>领单人：</span>
                <input id="keyUserId" name="keyUserId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="true" showNullItem="true" nullItemText="请选择..."/>
                <div style="margin-top: 5px"></div>
                <span>领单日期：</span>
                <input id="keyStartReceiveDate" name="keyStartReceiveDate" class="mini-datepicker"   format="yyyy-MM-dd"/>
                --
                <input id="keyEndReceiveDate" name="keyEndReceiveDate" class="mini-datepicker"  format="yyyy-MM-dd"/>

                <span class="separator"></span>
                <% if(so.hasPermission("bNativeBillCode:query")){%>
                    <a class="mini-button" iconCls="icon-add" onclick="searchCode()">查询</a>
                <% } %>

                <% if(so.hasPermission("bNativeBillCode:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <% if(so.hasPermission("bNativeBillCode:delete")){%>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-remove" onclick="deleteNativeBillCode()">删除</a>
                <% } %>
            </div>
        </div>

        <div class = "mini-fit">
            <div id="codeDatagrid" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/bill_code_manage/b_native/queryBillNativeCodeList" idField="id"
                 showPager="true" pageSize="20" sizeList="[20,30,40,50,100]"
                 allowResize="true"
                 multiSelect = "true"
                 allowCellWrap="true">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="id" width="140" headerAlign="center" align="center" allowSort="true">分单号</div>
                    <div field="useStatusId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">使用状态</div>
                    <div field="generateDepartmentId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"department"}' renderer="commonRender">领单部门</div>
                    <div field="generateDate" width="140" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">领单日期</div>
                    <div field="generateUserId" width="140" headerAlign="center" align="center" data-options='{cacheName:"sysUser"}' renderer="commonRender">领单人</div>
                    <div field="useDepartmentId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"department"}' renderer="commonRender">使用部门</div>
                    <div field="useUserId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">使用人</div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            mini.parse();
            let keyId = mini.get("keyId");
            let keyDepartmentId = mini.get("keyDepartmentId");
            let keyUseStatusId = mini.get("keyUseStatusId");
            let keyUserId = mini.get("keyUserId");
            let keyStartReceiveDate = mini.get("keyStartReceiveDate");
            let keyEndReceiveDate = mini.get("keyEndReceiveDate");
            let codeDatagrid = mini.get("codeDatagrid");

            let billNativeCodeForm = new mini.Form("#billNativeCodeForm");

            $(function () {
                // 使用状态初始化
                let useStatusJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_USE_STATUS");
                keyUseStatusId.load(useStatusJsonData);
                // 部门下拉列表初始化
                let xtDepartmentJsonData=commonRenderDropList("department");
                keyDepartmentId.loadList(xtDepartmentJsonData,"id","pid");
                // 用户初始化
                let xtUserJsonData=commonRenderDropList("sysUser");
                keyUserId.load(xtUserJsonData);

                // 加载列表数据
                codeDatagrid.load();
            });


            /**
             * 根据条件查询单号
             */
            function searchCode() {
                let data = billNativeCodeForm.getData(true);
                data.keyStartReceiveDate = keyStartReceiveDate.getFormValue().trim();
                data.keyEndReceiveDate = keyEndReceiveDate.getFormValue().trim();
                // 加载数据
                codeDatagrid.load(data);
            }


            function clearSearch() {
                let form = new mini.Form("#billNativeCodeForm");
                form.clear();
            }

            /**
             * 240,0,使用状态,使用状态,XT_DIC_USE_STATUS
             241,240,未使用,未使用,""
             242,240,已使用,已使用,""
             */
            let userStatus = {noUse:241,used:242};

             /**
             * 删除分单号
             */
            function deleteNativeBillCode(){
                let selectItems = codeDatagrid.getSelecteds();
                //useStatusId
                if(selectItems.length == 0){
                    showAlert("请选择需要删除的分单号!");
                    return;
                }

                let canNotDeleteCodes = "";
                let canDeleteCodes = "";

                for(let obj of selectItems){
                    if(obj.useStatusId == userStatus.used){
                        canNotDeleteCodes += obj.id + ",";
                    }
                    else{
                        canDeleteCodes += obj.id + ",";
                    }
                }


                if(canNotDeleteCodes.length>0){
                    canNotDeleteCodes = canNotDeleteCodes.substr(0,canNotDeleteCodes.length-1);
                    showAlert("选择的分单号【" + canNotDeleteCodes +"】已经被使用，不能删除!");
                    return;
                }

                if(canDeleteCodes.length == 0){
                    return;
                }

                 canDeleteCodes = canDeleteCodes.substr(0,canDeleteCodes.length-1);

                 mini.confirm("确定删除已经选择的分单号？", "分单号删除",
                     function (action) {
                         if (action == "ok") {
                             let ret = public_getServerData("${base}/pages/bill_code_manage/b_native/deleteNativeBillCode",{deleteNativeBillCodes:canDeleteCodes});
                             showAlert(ret.message,function (){
                                 if(ret.ok){
                                     codeDatagrid.reload();
                                 }
                             });
                         }
                     }
                 );
            }

        </script>
    </body>
</html>